home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows (5th Edition) / Programming Windows, 5th ed. - Companion CD (097-0002183)(1999).iso / Chap13 / PopPad / PopFont.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-09  |  1.6 KB  |  60 lines

  1. /*------------------------------------------
  2.    POPFONT.C -- Popup Editor Font Functions
  3.   ------------------------------------------*/
  4.  
  5. #include <windows.h>
  6. #include <commdlg.h>
  7.  
  8. static LOGFONT logfont ;
  9. static HFONT   hFont ;
  10.  
  11. BOOL PopFontChooseFont (HWND hwnd)
  12. {
  13.      CHOOSEFONT cf ;
  14.      
  15.      cf.lStructSize    = sizeof (CHOOSEFONT) ;
  16.      cf.hwndOwner      = hwnd ;
  17.      cf.hDC            = NULL ;
  18.      cf.lpLogFont      = &logfont ;
  19.      cf.iPointSize     = 0 ;
  20.      cf.Flags          = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS | CF_EFFECTS ;
  21.      cf.rgbColors      = 0 ;
  22.      cf.lCustData      = 0 ;
  23.      cf.lpfnHook       = NULL ;
  24.      cf.lpTemplateName = NULL ;
  25.      cf.hInstance      = NULL ;
  26.      cf.lpszStyle      = NULL ;
  27.      cf.nFontType      = 0 ;               // Returned from ChooseFont
  28.      cf.nSizeMin       = 0 ;
  29.      cf.nSizeMax       = 0 ;
  30.      
  31.      return ChooseFont (&cf) ;
  32. }
  33.  
  34. void PopFontInitialize (HWND hwndEdit)
  35. {
  36.      GetObject (GetStockObject (SYSTEM_FONT), sizeof (LOGFONT), 
  37.                 (PTSTR) &logfont) ;
  38.  
  39.      hFont = CreateFontIndirect (&logfont) ;
  40.      SendMessage (hwndEdit, WM_SETFONT, (WPARAM) hFont, 0) ;
  41. }
  42.  
  43. void PopFontSetFont (HWND hwndEdit)
  44. {
  45.      HFONT hFontNew ;
  46.      RECT  rect ;
  47.      
  48.      hFontNew = CreateFontIndirect (&logfont) ;
  49.      SendMessage (hwndEdit, WM_SETFONT, (WPARAM) hFontNew, 0) ;
  50.      DeleteObject (hFont) ;
  51.      hFont = hFontNew ;
  52.      GetClientRect (hwndEdit, &rect) ;
  53.      InvalidateRect (hwndEdit, &rect, TRUE) ;
  54. }
  55.  
  56. void PopFontDeinitialize (void)
  57. {
  58.      DeleteObject (hFont) ;
  59. }
  60.